package com.after.saas.system.mapper;

import com.after.saas.common.model.query.CommonQuery;
import com.after.saas.common.model.vo.AlipayRecordVO;
import com.after.saas.system.model.AlipayRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author hjchen
 * @since 2021-07-17
 */
public interface AlipayRecordMapper extends BaseMapper<AlipayRecord> {

    List<AlipayRecordVO> getYearIncome();

    List<AlipayRecordVO>  getYearExpend();

    List<AlipayRecordVO> getYear(CommonQuery query);

    List<AlipayRecordVO> getMonth(CommonQuery query);

    List<AlipayRecordVO>  getMonthIncome(CommonQuery query);

    List<AlipayRecordVO>  getMonthExpend(CommonQuery query);

    @Select({
            "<script>"
            +"SELECT" +
                    "        DATE_FORMAT(create_time, '%Y') perYear," +
                    "        trade_type," +
                    "        ROUND(SUM(money) ,2) total" +
                    "        FROM" +
                    "        sys_alipay_record" +
                    "        WHERE" +
                    "        create_time >= DATE_SUB(now(), INTERVAL 7 YEAR)" +
                    "        AND trade_type in ('支出','收入')" +
                    "        <if test='account!=null and account.length()>0'>" +
                    "            AND  account=#{account}" +
                    "        </if>"+
            "</script>"
    })
    List<AlipayRecordVO> getYearByStr(CommonQuery query);


}
